#pragma once

#include <wx/wx.h>
#include <wx/ffile.h>
#include <wx/zstream.h>
#include <wx/wfstream.h>
#include <wx/regex.h>

const wxString bgl_language[] = {
    _T("English"), 
    _T("French"),
    _T("Italian"),
    _T("Spanish"),
    _T("Dutch"),
    _T("Portuguese"),
    _T("German"),
    _T("Russian"),
    _T("Japanese"),
    _T("Traditional Chinese"),
    _T("Simplified Chinese"),
    _T("Greek"),
    _T("Korean"),
    _T("Turkish"),
    _T("Hebrew"),
    _T("Arabic"),
    _T("Thai"),
    _T("Other"),
    _T("Other Simplified Chinese dialects"),
    _T("Other Traditional Chinese dialects"),
    _T("Other Eastern-European languages"),
    _T("Other Western-European languages"),
    _T("Other Russian languages"),
    _T("Other Japanese languages"),
    _T("Other Baltic languages"),
    _T("Other Greek languages"),
    _T("Other Korean dialects"),
    _T("Other Turkish dialects"),
    _T("Other Thai dialects"),
    _T("Polish"),
    _T("Hungarian"),
    _T("Czech"),
    _T("Lithuanian"),
    _T("Latvian"),
    _T("Catalan"),
    _T("Croatian"),
    _T("Serbian"),
    _T("Slovak"),
    _T("Albanian"),
    _T("Urdu"),
    _T("Slovenian"),
    _T("Estonian"),
    _T("Bulgarian"),
    _T("Danish"),
    _T("Finnish"),
    _T("Icelandic"),
    _T("Norwegian"),
    _T("Romanian"),
    _T("Swedish"),
    _T("Ukrainian"),
    _T("Belarusian"),
    _T("Farsi"),
    _T("Basque"),
    _T("Macedonian"),
    _T("Afrikaans"),
    _T("Faeroese"),
    _T("Latin"),
    _T("Esperanto"),
    _T("Tamazight"),
    _T("Armenian")
    };

const wxString bgl_charsetname[] = {
	_T("Default"),
	_T("Latin"),
	_T("Eastern European"),
	_T("Cyrillic"),
	_T("Japanese"),
	_T("Traditional Chinese"),
	_T("Simplified Chinese"),
	_T("Baltic"),
	_T("Greek"),
	_T("Korean"),
	_T("Turkish"),
	_T("Hebrew"),
	_T("Arabic"),
	_T("Thai") };

const wxString bgl_charset[] = {
	_T("ISO-8859-1"), /*Default*/
	_T("ISO-8859-1"), /*Latin*/
	_T("ISO-8859-2"), /*Eastern European*/
	_T("WINDOWS-1251"), /*Cyriilic*/
	_T("SHIFT_JIS"), /*Japanese*/
	_T("CP950"), /*Traditional Chinese*/
	_T("CP936"), /*Simplified Chinese*/
	_T("CP1257"), /*Baltic*/
	_T("CP1253"), /*Greek*/
	_T("ISO-8859-15"),  /*Korean*/
	_T("ISO-8859-9"), /*Turkish*/
	_T("ISO-8859-9"), /*Hebrew*/
	_T("CP1256"), /*Arabic*/
	_T("CP874")  /*Thai*/ };

const wxString partOfSpeech[] = {
  _T("n."),
  _T("adj."),
  _T("v."),
  _T("adv."),
  _T("interj."),
  _T("pron."),
  _T("prep."),
  _T("conj."),
  _T("suff."),
  _T("pref."),
  _T("art.") };

typedef struct {
        unsigned type;
        unsigned length;
        char * data;
} bgl_block;

typedef struct {
        wxString headword;
        wxString definition;
} bgl_entry;

class BGLFile {
    public:
        BGLFile(wxString, const wxString &source_charset,
                const wxString &target_charset);
        ~BGLFile();

        bool open();
        void close();
        bgl_entry readEntry();
        bool read_info();
        
        bool readBlock(bgl_block &block);

        wxString file_name;
        wxString title;
        wxString author;
        wxString email;
        wxString description;
        wxString copyright;
        wxString sourceLang;
        wxString targetLang;
        wxString defaultCharset;
        wxString sourceCharset;
        wxString targetCharset;

    private:
        unsigned int read_number(int);

        unsigned int numEntries;
        // gzFile file;
        wxFFile raw_file;

        wxFFileInputStream* filestream;
        wxZlibInputStream* gzipstream;
        
        wxRegEx phonetic_u_reg; // fix the problem introduced by
                                // Babylon_Chinese_S_English and/or
                                // Babylon_Chinese_T_English
};

